package com.vecspace.dayu.code.pojo;

import java.io.File;
import java.util.Date;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.vecspace.dicttable.DictAll;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** DAYU-功能定义
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_FUNC")
public class Func implements IdEntity, java.io.Serializable {

	private static final long serialVersionUID = -4091081242812518411L;
	public Func(){
	}
	
	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}

	private Long projectId;
	/**项目ID*/
	@Column(name = "PROJECT_ID")
	public Long getProjectId(){
		return projectId;
	}
	/**项目ID*/
	public void setProjectId(Long value){
		this.projectId = value;
	}

	private String name;
	/**功能名称*/
	@Column(name = "NAME_")
	public String getName(){
		return name;
	}
	/**功能名称*/
	public void setName(String value){
		this.name = value;
	}

	private Long parentId;
	/**上级功能ID*/
	@Column(name = "PARENT_ID")
	public Long getParentId(){
		return parentId;
	}
	/**上级功能ID*/
	public void setParentId(Long value){
		this.parentId = value;
	}
	
	/**功能类型：1页面 2菜单项*/
	private Integer funcType;
	
	/**功能类型：1页面 2菜单项*/
	@Column(name = "FUNC_TYPE")
	public Integer getFuncType() {
		return funcType;
	}
	/**功能类型：1页面 2菜单项*/
	public void setFuncType(Integer funcType) {
		this.funcType = funcType;
	}

	private String tablesRelation;
	/** 1单表，2目录+叶子表，3主表+从表  TablesRelation*/
	@Column(name = "TABLES_RELATION")
	public String getTablesRelation() {
		return tablesRelation;
	}
	/** 1单表，2目录+叶子表，3主表+从表 TablesRelation */
	public void setTablesRelation(String tablesRelation) {
		this.tablesRelation = tablesRelation;
	}
	public static String TablesRelationCode="DAYU-CODE-003";
	@Transient
	public String getTablesRelationCaption() {
		return DictAll.getCachedItemName(TablesRelationCode, tablesRelation);
	}

	private String javaPkg;
	/**Java包名称*/
	@Column(name = "JAVA_PKG")
	public String getJavaPkg(){
		return javaPkg;
	}
	/**Java包名称*/
	public void setJavaPkg(String value){
		this.javaPkg = value;
	}

	private String fileName;
	/**页面主文件名*/
	@Column(name = "FILE_NAME")
	public String getFileName(){
		return fileName;
	}
	/**页面主文件名*/
	public void setFileName(String value){
		this.fileName = value;
	}
	
	private Long webPageLayoutId;
	private Long appPageLayoutId;
	private Long padPageLayoutId;
	
	/**主页面布局*/
	@Column(name = "WEB_PAGE_LAYOUT_ID")
	public Long getWebPageLayoutId(){
		return webPageLayoutId;
	}
	/**主页面布局*/
	public void setWebPageLayoutId(Long value){
		this.webPageLayoutId = value;
	}

	/**主页面布局*/
	@Column(name = "APP_PAGE_LAYOUT_ID")
	public Long getAppPageLayoutId(){
		return appPageLayoutId;
	}
	/**主页面布局*/
	public void setAppPageLayoutId(Long value){
		this.appPageLayoutId = value;
	}	
	/**主页面布局*/
	@Column(name = "PAD_PAGE_LAYOUT_ID")
	public Long getPadPageLayoutId(){
		return padPageLayoutId;
	}
	/**主页面布局*/
	public void setPadPageLayoutId(Long value){
		this.padPageLayoutId = value;
	}	
	
//	private Integer dataTableRelation;
//	/**涉及数据表关系*/
//	@Column(name = "TablesRelation")
//	public Integer getDataTableRelation(){
//		return dataTableRelation;
//	}
//	/**涉及数据表关系*/
//	public void setDataTableRelation(Integer value){
//		this.dataTableRelation = value;
//	}

	private Integer pageLang;
	/**页面语言*/
	@Column(name = "PAGE_LANG")
	public Integer getPageLang(){
		return pageLang;
	}
	/**页面语言*/
	public void setPageLang(Integer value){
		this.pageLang = value;
	}

	private String wfCode;
	/**工作流流程编号*/
	@Column(name = "WF_CODE")
	public String getWfCode(){
		return wfCode;
	}
	/**工作流流程编号*/
	public void setWfCode(String value){
		this.wfCode = value;
	}

	private String tips;
	/**功能说明*/
	@Column(name = "TIPS")
	public String getTips(){
		return tips;
	}
	/**功能说明*/
	public void setTips(String value){
		this.tips = value;
	}

	private String configStatus;
	public final static String ConfigStatusCode = "DAYU-CODE-002";
	/**功能配置状态,codetype=dayu-CODE-002 0未完成 1已完成*/
	@Column(name = "CONFIG_STATUS")
	public String getConfigStatus() {
		return configStatus;
	}
	/**功能配置状态,codetype=dayu-CODE-002 0未完成 1已完成*/
	public void setConfigStatus(String configStatus) {
		this.configStatus = configStatus;
	}
	@Transient
	public String getConfigStatusCaption(){
		return DictAll.getCachedItemName(ConfigStatusCode, configStatus);
	}

	private String remarks;
	/**备注*/
	@Column(name = "REMARKS")
	public String getRemarks(){
		return remarks;
	}
	/**备注*/
	public void setRemarks(String value){
		this.remarks = value;
	}

	private Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}
	
	
	private Integer delTag = 0;
	/**删除标记,0未删除，1已删除*/
	@Column(name = "DEL_TAG")
	public Integer getDelTag(){
		return delTag;
	}
	/**删除标记,0未删除，1已删除*/
	public void setDelTag(Integer value){
		this.delTag = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	
	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.projectId = rowMapper.getLong("PROJECT_ID");
		this.name = rowMapper.getString("NAME_");
		this.parentId = rowMapper.getLong("PARENT_ID");
		this.tablesRelation = rowMapper.getString("TABLES_RELATION");
		this.javaPkg = rowMapper.getString("JAVA_PKG");
		this.fileName = rowMapper.getString("FILE_NAME");
		this.webPageLayoutId = rowMapper.getLong("WEB_PAGE_LAYOUT_ID");
		this.appPageLayoutId = rowMapper.getLong("APP_PAGE_LAYOUT_ID");
		this.padPageLayoutId = rowMapper.getLong("PAD_PAGE_LAYOUT_ID");
		this.pageLang = rowMapper.getInteger("PAGE_LANG");
		this.configStatus = rowMapper.getString("CONFIG_STATUS");
		this.wfCode = rowMapper.getString("WF_CODE");
		this.tips = rowMapper.getString("TIPS");
		this.remarks = rowMapper.getString("REMARKS");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.delTag = rowMapper.getInteger("DEL_TAG");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}
	@Transient
	public String getViewPath() {
		if(StringUtils.isBlank(javaPkg))return "";
		String pkg = javaPkg.trim();
		String[] pkgSegments = pkg.split("\\.");
		
		String viewPath = pkgSegments[pkgSegments.length - 1];
		if(pkgSegments.length> 3) {
			viewPath = pkgSegments[pkgSegments.length - 2] + File.pathSeparatorChar + viewPath;
		}
		if(pkgSegments.length> 4) {
			viewPath = pkgSegments[pkgSegments.length - 3] + File.pathSeparatorChar + viewPath;
		}
		return viewPath;
	}
	
	@Transient
	public String getJavaPkgAsPath() {
		if(javaPkg == null || javaPkg.length() == 0)return "";
		return javaPkg.replace(".", File.separator);
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		Func other = (Func)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
